<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** @see Zend_DataGrid_Renderer_Html */
require_once 'Zend/DataGrid/Renderer/Html.php';


/**
 * Zend_DataGrid_Renderer_Html_AssocColumns
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: AssocColumns.php 8862 2008-11-15 15:36:00Z azoungrana $
 */
class Zend_DataGrid_Renderer_Html_AssocColumns extends Zend_DataGrid_Renderer_Html
{

    /**
     * Renders the header
     *
     * @return string
     */
    public function renderHeader()
    {
        $options = $this->_options;
        if (!$options['showHeader'])  return '';

        $assocColum = $this->_gridElement;
        $order = $assocColum->getColumnsOrder();

        $nbCol = 0;
        foreach ($assocColum->getColumns() as $asCol) {
            if ($asCol->getVisible()) $nbCol++;
        }
        if ($nbCol) {
            $options['headerAttributes'] = array_merge($options['headerAttributes'], array('colspan' => $nbCol));
            $this->_options = $options;
        }

        $content = '';
        $content .= '<th ' . $this->_htmlAttribs($options['headerAttributes']) . '>';
        $content .= parent::renderHeader();
        $content .= '</th>';

        return $content;
    }

   /**
     * Renders the cell
     *
     * @param mixed $rowData
     * @return string
     */
    public function renderItem($rowData, $isAlternatingItem = false)
    {
        $assocColum = $this->_gridElement;
        $order = $assocColum->getColumnsOrder();
        $options = $this->_options;

        $content = '';

        $assocColum->rewind();
        while ($assocColum->valid()) {
            $column = $assocColum->current();
            $content .= $column->getRenderer($this->getType())->renderItem($rowData, $isAlternatingItem);
            $assocColum->next();
        }

        return $content;
    }

   /**
     * Renders the footer
     *
     * @return string
     */
    public function renderFooter()
    {
        $options = $this->_options;
        if (!$options['showFooter'])  return '';

        $assocColum = $this->_gridElement;
        $order = $assocColum->getColumnsOrder();

        $nbCol = 0;
        foreach ($assocColum->getColumns() as $asCol) {
            if ($asCol->getVisible()) $nbCol++;
        }
        if ($nbCol) {
            $options['footerAttributes'] = array_merge($options['footerAttributes'], array('colspan' => $nbCol));
            $this->_options = $options;
        }

        $content = '';
        $content .= '<th ' . $this->_htmlAttribs($options['footerAttributes']) . '>';
        $content .= parent::renderFooter();
        $content .= '</th>';

        return $content;
    }

}




